package com.eati.cm.serv.dispacher;

import org.hibernate.ObjectNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

@Component
public class DispMan {

    @Autowired
    ApplicationContext ac;

    public Object getDisp(String dispName){
        Map<String, Object> dispBeanList = ac.getBeansWithAnnotation(Disp.class);
        System.out.println(dispBeanList);
        Set<Map.Entry<String, Object>> entrySet = dispBeanList.entrySet();
        Iterator<Map.Entry<String, Object>> it = entrySet.iterator();
        while(it.hasNext()){
            Map.Entry<String, Object> curr = it.next();
            System.out.println(curr.getKey());
            if(curr.getKey().equals(dispName)){
                return curr.getValue();
            }
        }

        throw new ObjectNotFoundException(dispName, "Disp named " + dispName + " not found!");
    }
}
